<?php
/*
  Plugin Name: Douban 
  Plugin URI: http://www.hengha.info
  Description: crawl books from http://www.douban.com
  Version: 1.0
  Author: tomcat
  Author URI: http://www.hengha.info
*/

require_once(ABSPATH.'wp-admin/includes/taxonomy.php');

function cron_add_small_interval( $schedules ) {
    if(!isset($schedules['ten-minutes'])){
        $schedules['ten-minutes'] = array(
            'interval' => 600,
            'display' =>__('Ten Minutes')
        );
    }
    if(!isset($schedules['three-minutes'])){
        $schedules['three-minutes'] = array(
            'interval' => 180,
            'display' =>__('Three Minutes')
        );
    }
    
    return $schedules;
}
add_filter( 'cron_schedules', 'cron_add_small_interval' );
function prefix_activation()
{
    wp_schedule_event(time(), 'hourly', 'douban_hourly_event_hook');
    wp_schedule_event(time(), 'three-minutes', 'douban_three_minutes_event_hook');
}
register_activation_hook(__FILE__, 'prefix_activation');

add_action('douban_hourly_event_hook', 'douban_get_list');
add_action('douban_three_minutes_event_hook', 'douban_get_item');


function douban_get_categories(){
    $categories=array();
    foreach(get_categories(array('taxonomy'=>'spectre_group','hide_empty'=>false)) as $category){
        $categories[$category->name]=$category->cat_ID;
        if($category->description&&!empty($category->description)){
            $aliases=json_decode($category->description);
            foreach($aliases as $alias){
                $categories[$alias]=$category->cat_ID;
            }
        }
    }
    return $categories;
}
function douban_save_category(){
    $cat=get_category('Image');
    wp_insert_category(array(
        'cat_ID'=>0,
        'cat_name'=>'Image',
        'category_parent'=>0,
        'taxonomy'=>'spectre_group'
    ));
}
function douban_get_list(){
}
function douban_get_item(){
}
function prefix_deactivation() {
    wp_clear_scheduled_hook( 'douban_hourly_event_hook');
    wp_clear_scheduled_hook( 'douban_three_minutes_event_hook');
}
register_deactivation_hook( __FILE__, 'prefix_deactivation' );
